package thread1;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class pool1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(10);

        for (int i =0;i<8;i++){
            pool.execute(()->{
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName());
            });

        }

        Future<Integer> submit = pool.submit(() -> {
            int sum = 0;
            for (int i = 0; i < 20; i++) {
                if (i % 2 != 0) {
                    sum = sum + i;
                }
            }
            return sum;
        });
        System.out.println(submit.get());
//        pool.shutdown();
    }

}

